<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list'){
	
	$return['list']=pdo_fetchall('SELECT g.goodsid,SUM(g.total) as total,g.price FROM '.tablename('jy_weishop_order_goods').' as g  left join '.tablename('jy_weishop_order').' as o on o.id = g.orderid WHERE  o.ispay= 1 and o.uniacid= '.$_SESSION['uniacid'].' group by g.goodsid');
	foreach($return['list'] as &$v){
		$good=pdo_get('jy_weishop_goods',array('id'=>$v['goodsid']),array('title','image','readnum'));
		$v['title']=$good['title'];
		$v['readnum']=$good['readnum'];
		$v['image']=$good['image'];
		$v['rate']=price($v['total']/$v['readnum']*100);
		
	}
	paixu($return['list'],'rate','desc');
	foreach($return['list'] as $k=>&$v){
		$v['rank']=$k+1;
	}
	$total=sizeof($return['list']);
	$totalpage=ceil($total/10);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =max(1, intval($_RQ['page']));;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排行','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'image','title'=>'商品图片','type'=>'image'),	
			array('name'=>'readnum','title'=>'访问量','type'=>'string'),			
			array('name'=>'total','title'=>'销售量','type'=>'string'),
			array('name'=>'rate','title'=>'转换率(%)','type'=>'string'),
			
		)),
	
	);

	$return['htmls']=$htmls;
	
	exi($return);
}
